package com.ymatou.iapi.trading.sellerquery.testcase;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.query.seller.trading.api.parameter.FundSummary;
import com.ymatou.query.seller.trading.api.parameter.GetSellerOrdersBean;
import com.ymatou.query.seller.trading.api.parameter.JsonOrderBean;
import com.ymatou.query.seller.trading.api.parameter.Pagination;
import com.ymatou.query.seller.trading.api.parameter.Sp_GetOrdersByOrderIds_v2;
import com.ymatou.query.seller.trading.api.parameter.Seller.Common;
import com.ymatou.query.seller.trading.api.parameter.info.OrderBasicInfo;
import com.ymatou.query.seller.trading.api.parameter.info.OrderConsigneeInfo;
import com.ymatou.query.seller.trading.api.parameter.info.OrderConsumerInfo;
import com.ymatou.query.seller.trading.api.parameter.info.OrderPaymentDetail;
import com.ymatou.query.seller.trading.api.parameter.info.OrderPaymentInfo;
import com.ymatou.query.seller.trading.api.parameter.info.OrderProductInfo;
import com.ymatou.query.seller.trading.api.parameter.info.OrderSellerInfo;
import com.ymatou.query.seller.trading.api.parameter.info.OrderTransferInfo;
import com.ymatou.query.seller.trading.api.parameter.info.SellerOrderInfo;
import com.ymatou.query.seller.trading.api.parameter.resp.GetSellerOrdersResponse;
import com.ymatou.query.seller.trading.api.service.OrderCreate;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.common.enums.OrderQueryStatusEnum;
import com.ymttest.common.enums.OrderQueryTimeTypeEnum;
import com.ymttest.common.enums.OrderStatusEnum;
import com.ymttest.common.enums.OrderTypeEnum;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.database.sqlwapper.YmtOrdersWapper;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.YMTDateUtil;
import com.ymttest.utils.constant.ECode;

/**
 * 根据卖家ID批量查询订单 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_GetSellerOrders {
	private static GetSellerOrdersBean getsellerordersBean;
	private static com.ymatou.query.seller.trading.api.service.GetSellerOrdersCall getsellerordersCall;
//	private static com.ymatou.iapi.trading.sellerquery.service.GetSellerOrdersCall getsellerordersCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据卖家ID批量查询订单");
	}

	@Before
	public void caseUp() {
		getsellerordersBean = new GetSellerOrdersBean();
		getsellerordersCall = new com.ymatou.query.seller.trading.api.service.GetSellerOrdersCall();
//		getsellerordersCall = new com.ymatou.iapi.trading.sellerquery.service.GetSellerOrdersCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getsellerordersCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	private void verify() {
		GetSellerOrdersResponse expectedResponse = new GetSellerOrdersResponse();
		ConstructExpectedResponse(expectedResponse);
		GetSellerOrdersResponse actualResponse = getsellerordersCall
				.getSellerOrdersResponse();
		DataUtil.verifyEquals(expectedResponse.getTotalOrdersCount(),
				actualResponse.getTotalOrdersCount(), "验证TotalOrdersCount");
		if (expectedResponse.getOrders() == null) {
			DataUtil.verifyEquals(null, actualResponse.getOrders(),
					"验证期望的Orders=null");
		} else {
			DataUtil.verifyEquals(expectedResponse.getOrders().size(),
					actualResponse.getOrders().size(), "验证Orders的数量");
			boolean flag = expectedResponse.getOrders().size() == actualResponse
					.getOrders().size();
			if (flag) {
				for (int i = 0; i < expectedResponse.getOrders().size(); i++) {
					SellerOrderInfo expect = expectedResponse.getOrders()
							.get(i);
					int expectId = expect.getBasic().getID();
					// DataUtil.verifyEquals(expect.getBasic().getID(),
					// actualResponse.getOrders().get(i).getBasic()
					// .getID(), "验证Orders中第" + (i + 1) + "条记录的排序");
					boolean exists = expectedResponse.getOrders().stream()
							.anyMatch(x -> x.getBasic().getID() == expectId);
					DataUtil.verifyEquals(true, exists, "验证Orders中存在Basic.ID=["
							+ expectId + "]的订单记录");
					if (exists) {
						SellerOrderInfo actual = expectedResponse.getOrders()
								.stream()
								.filter(x -> x.getBasic().getID() == expectId)
								.collect(Collectors.toList()).get(0);
						verifySellerOrderInfo(expect, actual, expectId);
					}
				}
			}
		}
	}

	public static void verifySellerOrderInfo(SellerOrderInfo expect,
			SellerOrderInfo actual, int expectId) {
		OrderBasicInfo expBasic = expect.getBasic();
		OrderBasicInfo actBasic = actual.getBasic();
		verifyBasic(expBasic, actBasic, expectId);
		OrderConsumerInfo expBuyer = expect.getBuyer();
		OrderConsumerInfo actBuyer = actual.getBuyer();
		verifyBuyer(expBuyer, actBuyer, expectId);
		OrderConsigneeInfo expConsignee = expect.getConsignee();
		OrderConsigneeInfo actConsignee = actual.getConsignee();
		verifyConsignee(expConsignee, actConsignee, expectId);
		OrderPaymentInfo expPayment = expect.getPayment();
		OrderPaymentInfo actPayment = actual.getPayment();
		verifyPayment(expPayment, actPayment, expectId);
		OrderSellerInfo expSeller = expect.getSeller();
		OrderSellerInfo actSeller = actual.getSeller();
		verifySeller(expSeller, actSeller, expectId);
		OrderTransferInfo expTransfer = expect.getTransfer();
		OrderTransferInfo actTransfer = actual.getTransfer();
		verifyTransfer(expTransfer, actTransfer, expectId);
		List<OrderProductInfo> expProducts = expect.getProducts();
		List<OrderProductInfo> actProducts = actual.getProducts();
		verifyProducts(expProducts, actProducts, expectId);
	}

	private static void verifyProducts(List<OrderProductInfo> expect,
			List<OrderProductInfo> actual, int expectId) {
		Logger.comment("开始验证id=[" + expectId + "]的Products对象");
		if (null == expect) {
			DataUtil.verifyDateEquals(null, actual, "验证id=[" + expectId
					+ "]Products=null");
		} else {
			DataUtil.verifyEquals(expect.size(), actual.size(), "验证id=["
					+ expectId + "]Products.size()");
			boolean flag = expect.size() == expect.size();
			if (flag) {
				for (OrderProductInfo exp : expect) {
					String expPid = exp.getProductId();
					boolean exists = actual.stream().anyMatch(
							x -> x.getProductId().equals(expPid));
					DataUtil.verifyEquals(true, exists, "验证id=[" + expectId
							+ "]的ProductId=[" + expPid + "]的Product记录是否存在");
					if (exists) {
						DataUtil.verify(true, actual.stream().anyMatch(x->x.equals(exp)), "验证\n"+exp+"\n是否存在于id=[" + expectId
							+ "]的products中");
					}
				}
			}
		}
		Logger.comment("完成验证id=[" + expectId + "]的Products对象");
	}

	private static Date getDate(String s) {
		if (null != s && "".equals(s) == false) {
			s = s.replaceAll("T", " ");
		}
		return YMTDateUtil.parseDate(s, YMTDateUtil.YMDHMS);
	}

	private static void verifyTransfer(OrderTransferInfo expect,
			OrderTransferInfo actual, int expectId) {
		Logger.comment("开始验证id=[" + expectId + "]的Transfer对象");
		DataUtil.verifyDateEquals(expect.getDeliveredTime(),
				actual.getDeliveredTime(), "验证id=[" + expectId
						+ "]Transfer.DeliveredTime");
		DataUtil.verifyDateEquals(expect.getReceiptConfirmedTime(),
				actual.getReceiptConfirmedTime(), "验证id=[" + expectId
						+ "]Transfer.ReceiptConfirmedTime");
		Logger.comment("完成验证id=[" + expectId + "]的Transfer对象");
	}

	private static void verifySeller(OrderSellerInfo expect,
			OrderSellerInfo actual, int expectId) {
		Logger.comment("开始验证id=[" + expectId + "]的Seller对象");
		DataUtil.verifyEquals(expect.getComment(), actual.getComment(),
				"验证id=[" + expectId + "]Seller.Comment");
		DataUtil.verifyEquals(expect.getEmail(), actual.getEmail(), "验证id=["
				+ expectId + "]Seller.Email");
		DataUtil.verifyEquals(expect.getID(), actual.getID(), "验证id=["
				+ expectId + "]Seller.ID");
		DataUtil.verifyEquals(expect.getLoginId(), actual.getLoginId(),
				"验证id=[" + expectId + "]Seller.LoginId");
		Logger.comment("完成验证id=[" + expectId + "]的Seller对象");
	}

	private static void verifyPayment(OrderPaymentInfo expect,
			OrderPaymentInfo actual, int expectId) {
		Logger.comment("开始验证id=[" + expectId + "]的Payment对象");
		DataUtil.verifyDecimalEquals(expect.getActualPaid(),
				actual.getActualPaid(), "验证id=[" + expectId
						+ "]的Payment.ActualPaid");
		List<OrderPaymentDetail> expDetails = expect.getDetails();
		List<OrderPaymentDetail> actDetails = actual.getDetails();
		if (expDetails == null) {
			DataUtil.verifyEquals(null, actDetails, "验证id=[" + expectId
					+ "]的Payment.Details = null");
		} else {
			boolean flag = expDetails.size() == actDetails.size();
			DataUtil.verifyEquals(expDetails.size(), actDetails.size(),
					"验证id=[" + expectId + "]的Payment.Details的Size()");
			if (flag) {
				for (OrderPaymentDetail exp : expDetails) {
					// for (int i=0;i< expDetails.size();i++) {
					// OrderPaymentDetail exp = expDetails.get(i);
					String expTime = exp.getPaidTime();
					Date expTimeDate = getDate(expTime);
					boolean exists = actDetails.stream().anyMatch(
							x -> getDate(x.getPaidTime())
									.compareTo(expTimeDate) == 0
									&& exp.getType() == x.getType());
					DataUtil.verifyEquals(expDetails.size(), actDetails.size(),
							"验证id=[" + expectId + "]的PaidTime=[" + expTime
									+ "]Payment.Details的记录是否存在()");
					if (exists) {
						OrderPaymentDetail act = actDetails
								.stream()
								.filter(x -> getDate(x.getPaidTime())
										.compareTo(expTimeDate) == 0
										&& exp.getType() == x.getType())
								.collect(Collectors.toList()).get(0);
						DataUtil.verifyEquals(exp.getExternalTradingNo(),
								act.getExternalTradingNo(), "验证id=[" + expectId
										+ "]的PaidTime=[" + expTime
										+ "]Payment.Details.ExternalTradingNo");
						DataUtil.verifyEquals(exp.getInternalTradingNo(),
								act.getInternalTradingNo(), "验证id=[" + expectId
										+ "]的PaidTime=[" + expTime
										+ "]Payment.Details.InternalTradingNo");
						DataUtil.verifyEquals(exp.getType(), act.getType(),
								"验证id=[" + expectId + "]的PaidTime=[" + expTime
										+ "]Payment.Details.Type");
					}
				}
			}
		}
		FundSummary expSummary = expect.getSummary();
		FundSummary actSummary = actual.getSummary();
		DataUtil.verifyDecimalEquals(expSummary.getFirstPayProductPrice(),
				actSummary.getFirstPayProductPrice(), "验证id=[" + expectId
						+ "]的Payment.Summary.FirstPayProductPrice");
		DataUtil.verifyDecimalEquals(expSummary.getFreight(),
				actSummary.getFreight(), "验证id=[" + expectId
						+ "]的Payment.Summary.Freight");
		DataUtil.verifyDecimalEquals(expSummary.getOrderDiscount(),
				actSummary.getOrderDiscount(), "验证id=[" + expectId
						+ "]的Payment.Summary.OrderDiscount");
		DataUtil.verifyDecimalEquals(expSummary.getPaidCash(),
				actSummary.getPaidCash(), "验证id=[" + expectId
						+ "]的Payment.Summary.PaidCash");
		DataUtil.verifyDecimalEquals(expSummary.getPaidFreeCard(),
				actSummary.getPaidFreeCard(), "验证id=[" + expectId
						+ "]的Payment.Summary.PaidFreeCard");
		DataUtil.verifyDecimalEquals(expSummary.getPaidGift(),
				actSummary.getPaidGift(), "验证id=[" + expectId
						+ "]的Payment.Summary.PaidGift");
		DataUtil.verifyDecimalEquals(expSummary.getPaidSellerCoupon(),
				actSummary.getPaidSellerCoupon(), "验证id=[" + expectId
						+ "]的Payment.Summary.PaidSellerCoupon");
		DataUtil.verifyDecimalEquals(expSummary.getPaidYmtCoupon(),
				actSummary.getPaidYmtCoupon(), "验证id=[" + expectId
						+ "]的Payment.Summary.PaidYmtCoupon");
		DataUtil.verifyDecimalEquals(expSummary.getPostPaidCash(),
				actSummary.getPostPaidCash(), "验证id=[" + expectId
						+ "]的Payment.Summary.PostPaidCash");
		DataUtil.verifyDecimalEquals(expSummary.getPostPaidGift(),
				actSummary.getPostPaidGift(), "验证id=[" + expectId
						+ "]的Payment.Summary.PostPaidGift");
		DataUtil.verifyDecimalEquals(expSummary.getPostPayDiscount(),
				actSummary.getPostPayDiscount(), "验证id=[" + expectId
						+ "]的Payment.Summary.PostPayDiscount");
		DataUtil.verifyDecimalEquals(expSummary.getTotalActivityPrice(),
				actSummary.getTotalActivityPrice(), "验证id=[" + expectId
						+ "]的Payment.Summary.TotalActivityPrice");
		DataUtil.verifyDecimalEquals(expSummary.getTotalCanceledCash(),
				actSummary.getTotalCanceledCash(), "验证id=[" + expectId
						+ "]的Payment.Summary.TotalCanceledCash");
		DataUtil.verifyDecimalEquals(expSummary.getTotalCanceledYmtCoupon(),
				actSummary.getTotalCanceledYmtCoupon(), "验证id=[" + expectId
						+ "]的Payment.Summary.TotalCanceledYmtCoupon");
		DataUtil.verifyDecimalEquals(expSummary.getTotalProductPrice(),
				actSummary.getTotalProductPrice(), "验证id=[" + expectId
						+ "]的Payment.Summary.TotalProductPrice");
		DataUtil.verifyDecimalEquals(expSummary.getTotalRefundedCash(),
				actSummary.getTotalRefundedCash(), "验证id=[" + expectId
						+ "]的Payment.Summary.TotalRefundedCash");
		DataUtil.verifyDecimalEquals(expSummary.getTotalRefundedGift(),
				actSummary.getTotalRefundedGift(), "验证id=[" + expectId
						+ "]的Payment.Summary.TotalRefundedGift");
		DataUtil.verifyDecimalEquals(expSummary.getTotalRefundedYmtCoupon(),
				actSummary.getTotalRefundedYmtCoupon(), "验证id=[" + expectId
						+ "]的Payment.Summary.TotalRefundedYmtCoupon");

		Logger.comment("完成验证id=[" + expectId + "]的Payment对象");
	}

	private static void verifyConsignee(OrderConsigneeInfo expect,
			OrderConsigneeInfo actual, int expectId) {
		Logger.comment("开始验证id=[" + expectId + "]的Consignee对象");
		DataUtil.verifyEquals(expect.getAddress(), actual.getAddress(),
				"验证id=[" + expectId + "]的Consignee.Address");
		DataUtil.verifyEquals(expect.getName(), actual.getName(), "验证id=["
				+ expectId + "]的Consignee.Name");
		DataUtil.verifyEquals(expect.getPhone(), actual.getPhone(), "验证id=["
				+ expectId + "]的Consignee.Phone");
		DataUtil.verifyEquals(expect.getPostcode(), actual.getPostcode(),
				"验证id=[" + expectId + "]的Consignee.Postcode");
		DataUtil.verifyEquals(expect.getTel(), actual.getTel(), "验证id=["
				+ expectId + "]的Consignee.Tel");
		Logger.comment("完成验证id=[" + expectId + "]的Consignee对象");
	}

	private static void verifyBuyer(OrderConsumerInfo expect,
			OrderConsumerInfo actual, int expectId) {
		Logger.comment("开始验证id=[" + expectId + "]的Buyer对象");
		DataUtil.verifyEquals(expect.getEmail(), actual.getEmail(), "验证id=["
				+ expectId + "]的Buyer.Email");
		DataUtil.verifyEquals(expect.getID(), actual.getID(), "验证id=["
				+ expectId + "]的Buyer.ID");
		DataUtil.verifyEquals(expect.getLoginId(), actual.getLoginId(),
				"验证id=[" + expectId + "]的Buyer.LoginId");
		DataUtil.verifyEquals(expect.getMessage(), actual.getMessage(),
				"验证id=[" + expectId + "]的Buyer.Message");
		DataUtil.verifyEquals(expect.getNickName(), actual.getNickName(),
				"验证id=[" + expectId + "]的Buyer.NickName");
		Logger.comment("完成验证id=[" + expectId + "]的Buyer对象");
	}

	private static void verifyBasic(OrderBasicInfo expect,
			OrderBasicInfo actual, int expectId) {
		Logger.comment("开始验证id=[" + expectId + "]的Basic对象");
		DataUtil.verifyDateEquals(expect.getAcceptedTime(),
				actual.getAcceptedTime(), "验证id=[" + expectId
						+ "]的Basic.AcceptedTime");
		DataUtil.verifyDateEquals(expect.getCancelledTime(),
				actual.getCancelledTime(), "验证id=[" + expectId
						+ "]的Basic.CancelledTime");
		DataUtil.verifyDateEquals(expect.getCreatedTime(),
				actual.getCreatedTime(), "验证id=[" + expectId
						+ "]的Basic.CreatedTime");
		DataUtil.verifyDecimalEquals(expect.getDiscount(),
				actual.getDiscount(), "验证id=[" + expectId + "]的Basic.Discount");
		DataUtil.verifyEquals(expect.getSource(), actual.getSource(), "验证id=["
				+ expectId + "]的Basic.Source");
		DataUtil.verifyEquals(expect.getStatus(), actual.getStatus(), "验证id=["
				+ expectId + "]的Basic.Status");
		DataUtil.verifyDecimalEquals(expect.getTotalPrice(),
				actual.getTotalPrice(), "验证id=[" + expectId
						+ "]的Basic.TotalPrice");
		DataUtil.verifyEquals(expect.getType(), actual.getType(), "验证id=["
				+ expectId + "]的Basic.Type");
		Logger.comment("完成验证id=[" + expectId + "]的Basic对象");
	}

	private void ConstructExpectedResponse(GetSellerOrdersResponse response) {
		Process(response);
	}

	private String time = "dAddTime";

	private void Process(GetSellerOrdersResponse response) {
		Pagination page = new Pagination(getsellerordersBean.getPageIndex(),
				getsellerordersBean.getPageSize());
		int status = DataUtil.Integerr.GetValueOrDefault(getsellerordersBean
				.getOrderStatus());
		Sp_GetOrdersByOrderIds_v2 result = execute(GetStatusCondition(status),
				GetTimeTypeField(getsellerordersBean.getTimeType()),
				GetLogisticsCondition(getsellerordersBean.getLogistics()),
				page, response);
		List<SellerOrderInfo> orders = Common.ConvertToSellerOrders(result);
		response.setOrders(orders);
	}

	@SuppressWarnings("rawtypes")
	private Sp_GetOrdersByOrderIds_v2 execute(String statusCondition,
			String timeCondition, String logisticsCondition, Pagination page,
			GetSellerOrdersResponse response) {
		StringBuffer sb1 = new StringBuffer();
		sb1.append("iBuyerId = " + getsellerordersBean.getSellerId());
		sb1.append(statusCondition);
		sb1.append(timeCondition);
		sb1.append(logisticsCondition);
		List<Map> totalOrders = new YmtOrdersWapper().selectOrders2(
				"o.iOrderId", null, sb1.toString());
		int totalOrdersCount = totalOrders.size();
		response.setTotalOrdersCount(totalOrdersCount);

		sb1.append(" order by " + this.time + " desc");
		sb1.append(" offset " + (page.getPageItemIndexFrom() - 1)
				+ " rows fetch next " + page.getPageSize() + " rows only");
		List<Integer> iOrderIds = new ArrayList<Integer>();
		List<Map> fetchOrders = new YmtOrdersWapper().selectOrders2(
				"o.iOrderId", null, sb1.toString());
		fetchOrders.stream().forEach(
				x -> iOrderIds.add((int) x.get("iOrderId")));
		Sp_GetOrdersByOrderIds_v2 sp = new Sp_GetOrdersByOrderIds_v2();
		sp.setOrders(iOrderIds);
		sp.setSeller(getsellerordersBean.getSellerId());
		return sp.execute();
	}

	private String GetStatusCondition(int status) {
		if (status == OrderStatusEnum.SellerAccept.getValue()) {
			return " and o.iTradingStatus = 17 and o.bPaidInFull = 1";
		} else if (status == OrderStatusEnum.OrderPostPay.getValue()) {
			return " and o.iTradingStatus = 17 and o.bPaidInFull = 0";
		}
		return " and o.iTradingStatus = " + status;
	}

	private String GetTimeTypeField(Integer timeType) {
		switch (timeType) {
		case 2:
			this.time = "dPaidTime";
			return " and dPaidTime >= '" + getsellerordersBean.getBeginTime()
					+ "' and dPaidTime < '" + getsellerordersBean.getEndTime()
					+ "'";
		case 5:
			this.time = "dAcceptTime";
			return " and dAcceptTime >= '" + getsellerordersBean.getBeginTime()
					+ "' and dAcceptTime < '"
					+ getsellerordersBean.getEndTime() + "'";
		}
		return " and dAddTime >= '" + getsellerordersBean.getBeginTime()
				+ "' and dAddTime < '" + getsellerordersBean.getEndTime() + "'";
	}

	private String GetLogisticsCondition(List<Integer> logisticsTypes) {
		if (DataUtil.isNullOrEmpty(logisticsTypes))
			return DataUtil.Stringg.Empty;

		StringBuffer cond = new StringBuffer(
				" and exists(select top 1 1 from ymt_orderinfo(nolock) i where i.iorderid = o.iorderid and i.icatalogstatus ");
		if (logisticsTypes.size() > 1) {
			cond.append(" in " + DataUtil.toInOfSql(logisticsTypes));
		}

		return cond.append(" )").toString();
	}

	// 根据总记录数，每页数 计算总共有多少页
	private int getTotalPage(int totalRecords, int pageSize) {
		int totalPage;
		if (totalRecords % pageSize > 0) {
			totalPage = (totalRecords / pageSize) + 1;
		} else {
			totalPage = (totalRecords / pageSize);
		}
		return totalPage;
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetSellerOrders_001() {
		Logger.start(true, "根据卖家ID批量查询订单成功");
		try {
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			Logger.comment("准备前置数据");
			OrderCreate c = new OrderCreate();
			c.createOrderWithSellerCoupon(userId, sellerId);
			Thread.sleep(5000l);
			Logger.comment("完成准备前置数据");

			getsellerordersBean.setSellerId(sellerId);
			int status = OrderQueryStatusEnum.OrderEstablish.getValue();
			getsellerordersBean.setOrderStatus(status);
			String beginTime = YMTDateUtil.getBeforeOrNextDay(-50).replace(' ', 'T');
			String endTime = YMTDateUtil.getBeforeOrNextDay(10).replace(' ', 'T');
			getsellerordersBean.setBeginTime(beginTime);
			getsellerordersBean.setEndTime(endTime);
			int timeType = OrderQueryTimeTypeEnum.CreateDate.getValue();
			getsellerordersBean.setTimeType(timeType);
			getsellerordersBean.setPageIndex(1);
			getsellerordersBean.setPageSize(10);
			getsellerordersCall.setData(getsellerordersBean);
			getsellerordersCall.callService();
			Logger.verifyEquals(ECode.SUCCESS, getsellerordersCall.getCode(),
					"验证Code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetSellerOrders_002() {
		Logger.start(true, "根据卖家ID+按下单时间查询");
		try {
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			Logger.comment("准备前置数据");
			OrderCreate c = new OrderCreate();
			c.create1_BatchC2COrder(userId, sellerId, 3);
			Thread.sleep(5000l);
			Logger.comment("完成准备前置数据");

			getsellerordersBean.setSellerId(sellerId);
			int status = OrderQueryStatusEnum.Received.getValue();
			getsellerordersBean.setOrderStatus(status);
			String beginTime = YMTDateUtil.getBeforeOrNextDay(-50).replace(' ', 'T');
			String endTime = YMTDateUtil.getBeforeOrNextDay(10).replace(' ', 'T');
			getsellerordersBean.setBeginTime(beginTime);
			getsellerordersBean.setEndTime(endTime);

			int timeType = OrderQueryTimeTypeEnum.CreateDate.getValue();

			getsellerordersBean.setTimeType(timeType);
			getsellerordersBean.setPageIndex(1);
			getsellerordersBean.setPageSize(10);

			getsellerordersCall.setData(getsellerordersBean);
			getsellerordersCall.callService();

			Logger.verifyEquals(ECode.SUCCESS, getsellerordersCall.getCode(),
					"验证Code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetSellerOrders_003() {
		Logger.start(true, "根据卖家ID,状态为已确认接单(等待发起补款)");
		try {
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			Logger.comment("准备前置数据");
			OrderCreate c = new OrderCreate();
			c.create101_WaitPostPayOrder(userId, sellerId);
			Thread.sleep(2000l);
			Logger.comment("完成准备前置数据");

			getsellerordersBean.setSellerId(sellerId);
			int status = OrderQueryStatusEnum.OrderPostPay.getValue();
			getsellerordersBean.setOrderStatus(status);
			String beginTime = YMTDateUtil.getBeforeOrNextDay(-5).replace(' ', 'T');
			String endTime = YMTDateUtil.getBeforeOrNextDay(10).replace(' ', 'T');
			getsellerordersBean.setBeginTime(beginTime);
			getsellerordersBean.setEndTime(endTime);

			int timeType = OrderQueryTimeTypeEnum.CreateDate.getValue();

			getsellerordersBean.setTimeType(timeType);
			// getsellerordersBean.setOrderType(orderType);
			getsellerordersBean.setPageIndex(2);
			getsellerordersBean.setPageSize(10);

			getsellerordersCall.setData(getsellerordersBean);
			getsellerordersCall.callService();

			Logger.verifyEquals(ECode.SUCCESS, getsellerordersCall.getCode(),
					"验证Code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetSellerOrders_004() {
		Logger.start(true, "根据卖家ID+状态等待发货+按付款时间查询");
		try {
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			Logger.comment("准备前置数据");
			OrderCreate c = new OrderCreate();
			c.create17_AcceptOrder(userId, sellerId);
			Thread.sleep(2000l);
			Logger.comment("完成准备前置数据");
			getsellerordersBean.setSellerId(sellerId);
			int status = OrderQueryStatusEnum.SellerAccept.getValue();
			getsellerordersBean.setOrderStatus(status);
			String beginTime = YMTDateUtil.getBeforeOrNextDay(-5).replace(' ', 'T');
			String endTime = YMTDateUtil.getBeforeOrNextDay(10).replace(' ', 'T');
			getsellerordersBean.setBeginTime(beginTime);
			getsellerordersBean.setEndTime(endTime);

			int timeType = OrderQueryTimeTypeEnum.PayDate.getValue();

			getsellerordersBean.setTimeType(timeType);
			// getsellerordersBean.setOrderType(orderType);
			getsellerordersBean.setPageIndex(1);
			getsellerordersBean.setPageSize(10);

			getsellerordersCall.setData(getsellerordersBean);
			getsellerordersCall.callService();

			Logger.verifyEquals(ECode.SUCCESS, getsellerordersCall.getCode(),
					"验证Code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetSellerOrders_005() {
		Logger.start(true, "根据卖家ID+状态已确认接单(等待发起补款)+按接单查询");
		try {
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			getsellerordersBean.setSellerId(sellerId);
			int status = OrderQueryStatusEnum.OrderPostPay.getValue();
			getsellerordersBean.setOrderStatus(status);
			String beginTime = YMTDateUtil.getBeforeOrNextDay(-50).replace(' ', 'T');
			String endTime = YMTDateUtil.getBeforeOrNextDay(10).replace(' ', 'T');
			getsellerordersBean.setBeginTime(beginTime);
			getsellerordersBean.setEndTime(endTime);
			int timeType = OrderQueryTimeTypeEnum.CreateDate.getValue();
			getsellerordersBean.setTimeType(timeType);
			getsellerordersBean.setPageIndex(1);
			getsellerordersBean.setPageSize(10);

			getsellerordersCall.setData(getsellerordersBean);
			getsellerordersCall.callService();

			Logger.verifyEquals(ECode.SUCCESS, getsellerordersCall.getCode(),
					"验证Code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetSellerOrders_006() {
		Logger.start(true, "根据卖家ID批量查询,每页显示数大于总记录数");
		try {
			int sellerId = Integer.valueOf(EnvSetup.getData("BuyerId"));
			getsellerordersBean.setSellerId(sellerId);
			int status = OrderQueryStatusEnum.OrderPostPay.getValue();
			getsellerordersBean.setOrderStatus(status);
			String beginTime = YMTDateUtil.getBeforeOrNextDay(-5).replace(' ', 'T');
			String endTime = YMTDateUtil.getBeforeOrNextDay(10).replace(' ', 'T');
			getsellerordersBean.setBeginTime(beginTime);
			getsellerordersBean.setEndTime(endTime);
			int timeType = OrderQueryTimeTypeEnum.PayDate.getValue();
			int orderType = OrderTypeEnum.Shangou.getValue();
			getsellerordersBean.setTimeType(timeType);
			// getsellerordersBean.setOrderType(orderType);

			HashMap m = new HashMap();
			m.put("sellerId", sellerId);
			m.put("tradingStatus", status);
			m.put("timeType", timeType);
			m.put("orderType", orderType);
			m.put("beginTime", beginTime);
			m.put("endTime", endTime);
			// 查询总共有多少条记录
			List<Map> dbOrderList = new DefaultWapper().selectOrderBySeller(m);
			int pageInde = 1;
			int pageSize = dbOrderList.size() + 1;
			getsellerordersBean.setPageIndex(pageInde);
			getsellerordersBean.setPageSize(pageSize);

			getsellerordersCall.setData(getsellerordersBean);
			getsellerordersCall.callService();

			Logger.verifyEquals(ECode.SUCCESS, getsellerordersCall.getCode(),
					"验证Code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetSellerOrders_007() {
		Logger.start(true, "查询校验验证第一第二页和最后一页数据");
		try {
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			getsellerordersBean.setSellerId(sellerId);
			int status = OrderQueryStatusEnum.OrderPostPay.getValue();
			getsellerordersBean.setOrderStatus(status);
			String beginTime = YMTDateUtil.getBeforeOrNextDay(-5).replace(' ', 'T');
			String endTime = YMTDateUtil.getBeforeOrNextDay(10).replace(' ', 'T');
			getsellerordersBean.setBeginTime(beginTime);
			getsellerordersBean.setEndTime(endTime);
			int timeType = OrderQueryTimeTypeEnum.PayDate.getValue();
			int orderType = OrderTypeEnum.Shangou.getValue();
			getsellerordersBean.setTimeType(timeType);
			HashMap m = new HashMap();
			m.put("sellerId", sellerId);
			m.put("tradingStatus", status);
			m.put("timeType", timeType);
			m.put("orderType", orderType);
			m.put("beginTime", beginTime);
			m.put("endTime", endTime);
			// 查询总共有多少条记录
			List<Map> dbOrderList = new DefaultWapper().selectOrderBySeller(m);
			int pageIndex = 1;
			int pageSize = 2;
			int dbTotalPage = getTotalPage(dbOrderList.size(), pageSize);
			Logger.comment("总共有:" + dbOrderList.size() + "页");

			ArrayList<JsonOrderBean> returnOrderList = new ArrayList<JsonOrderBean>();
			Set orderSet = new HashSet();
			int recordCount = 0;
			for (pageIndex = 1; pageIndex < dbTotalPage + 1; pageIndex++) {
				// 验证第一第二页和最后一页
				if (pageIndex <= 2 || pageIndex == dbTotalPage) {
					getsellerordersBean.setPageIndex(pageIndex);
					getsellerordersBean.setPageSize(pageSize);
					Logger.comment("第" + pageIndex + "页");
					getsellerordersCall.setData(getsellerordersBean);
					getsellerordersCall.callService();
					Logger.verifyEquals(ECode.SUCCESS,
							getsellerordersCall.getCode(), "验证Code");
					verify();
				}
			}
			Logger.verifyEquals(recordCount, orderSet.size(), "验证所有的分页的数据没有重复");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetSellerOrders_008() {
		Logger.start(false, "卖家id为null");
		try {
			int status = OrderQueryStatusEnum.SellerAccept.getValue();
			getsellerordersBean.setOrderStatus(status);
			String beginTime = YMTDateUtil.getBeforeOrNextDay(-5).replace(' ', 'T');
			String endTime = YMTDateUtil.getBeforeOrNextDay(10).replace(' ', 'T');
			getsellerordersBean.setBeginTime(beginTime);
			getsellerordersBean.setEndTime(endTime);
			int timeType = OrderQueryTimeTypeEnum.PayDate.getValue();
			getsellerordersBean.setTimeType(timeType);

			getsellerordersBean.setPageIndex(1);
			getsellerordersBean.setPageSize(10);

			getsellerordersCall.setData(getsellerordersBean);
			getsellerordersCall.callService();

			Logger.verifyEquals(ECode.ERROR400, getsellerordersCall.getCode(),
					"验证Code");
			Logger.verifyEquals(ECode.ERROR400_MSG_24,
					getsellerordersCall.getString("Msg"), "验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetSellerOrders_009() {
		Logger.start(false, "卖家id为0");
		try {
			getsellerordersBean.setSellerId(0);
			int status = OrderQueryStatusEnum.SellerAccept.getValue();
			getsellerordersBean.setOrderStatus(status);
			String beginTime = YMTDateUtil.getBeforeOrNextDay(-5).replace(' ', 'T');
			String endTime = YMTDateUtil.getBeforeOrNextDay(10).replace(' ', 'T');
			getsellerordersBean.setBeginTime(beginTime);
			getsellerordersBean.setEndTime(endTime);
			int timeType = OrderQueryTimeTypeEnum.PayDate.getValue();
			getsellerordersBean.setTimeType(timeType);

			getsellerordersBean.setPageIndex(1);
			getsellerordersBean.setPageSize(10);

			getsellerordersCall.setData(getsellerordersBean);
			getsellerordersCall.callService();

			Logger.verifyEquals(ECode.ERROR400, getsellerordersCall.getCode(),
					"验证Code");
			Logger.verifyEquals(ECode.ERROR400_MSG_24,
					getsellerordersCall.getString("Msg"), "验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetSellerOrders_010() {
		Logger.start(false, "订单状态为null");
		try {
			int sellerId = Integer.valueOf(EnvSetup.getData("BuyerId"));
			getsellerordersBean.setSellerId(sellerId);
			// getsellerordersBean.setOrderStatus(status);
			String beginTime = YMTDateUtil.getBeforeOrNextDay(-5).replace(' ', 'T');
			String endTime = YMTDateUtil.getBeforeOrNextDay(10).replace(' ', 'T');
			getsellerordersBean.setBeginTime(beginTime);
			getsellerordersBean.setEndTime(endTime);
			int timeType = OrderQueryTimeTypeEnum.PayDate.getValue();
			getsellerordersBean.setTimeType(timeType);
			// getsellerordersBean.setOrderType(orderType);

			getsellerordersBean.setPageIndex(1);
			getsellerordersBean.setPageSize(10);

			getsellerordersCall.setData(getsellerordersBean);
			getsellerordersCall.callService();

			Logger.verifyEquals(ECode.ERROR400, getsellerordersCall.getCode(),
					"验证Code");
			Logger.verifyEquals(ECode.ERROR400_MSG_27,
					getsellerordersCall.getString("Msg"), "验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetSellerOrders_011() {
		Logger.start(false, "时间类型为null");
		try {
			int sellerId = Integer.valueOf(EnvSetup.getData("BuyerId"));
			getsellerordersBean.setSellerId(sellerId);
			int status = OrderQueryStatusEnum.SellerAccept.getValue();
			getsellerordersBean.setOrderStatus(status);
			String beginTime = YMTDateUtil.getBeforeOrNextDay(-5).replace(' ', 'T');
			String endTime = YMTDateUtil.getBeforeOrNextDay(10).replace(' ', 'T');
			getsellerordersBean.setBeginTime(beginTime);
			getsellerordersBean.setEndTime(endTime);

			getsellerordersBean.setPageIndex(1);
			getsellerordersBean.setPageSize(10);

			getsellerordersCall.setData(getsellerordersBean);
			getsellerordersCall.callService();

			Logger.verifyEquals(ECode.ERROR400, getsellerordersCall.getCode(),
					"验证Code");
			Logger.verifyEquals(ECode.ERROR400_MSG_28,
					getsellerordersCall.getString("Msg"), "验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetSellerOrders_012() {
		Logger.start(false, "截止时间小于查询开始时间");
		try {
			int sellerId = Integer.valueOf(EnvSetup.getData("BuyerId"));
			getsellerordersBean.setSellerId(sellerId);
			int status = OrderQueryStatusEnum.SellerAccept.getValue();
			getsellerordersBean.setOrderStatus(status);
			String beginTime = YMTDateUtil.getBeforeOrNextDay(1).replace(' ', 'T');
			String endTime = YMTDateUtil.getBeforeOrNextDay(-1).replace(' ', 'T');
			getsellerordersBean.setBeginTime(beginTime);
			getsellerordersBean.setEndTime(endTime);
			int timeType = OrderQueryTimeTypeEnum.PayDate.getValue();
			int orderType = OrderTypeEnum.Shangou.getValue();
			getsellerordersBean.setTimeType(timeType);
			// getsellerordersBean.setOrderType(orderType);

			getsellerordersBean.setPageIndex(1);
			getsellerordersBean.setPageSize(10);

			getsellerordersCall.setData(getsellerordersBean);
			getsellerordersCall.callService();

			Logger.verifyEquals(ECode.ERROR400, getsellerordersCall.getCode(),
					"验证Code");
			Logger.verifyEquals(ECode.ERROR400_MSG_29,
					getsellerordersCall.getString("Msg"), "验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetSellerOrders_013() {
		Logger.start(false, "查询指定当前页数为0");
		try {
			int sellerId = Integer.valueOf(EnvSetup.getData("BuyerId"));
			getsellerordersBean.setSellerId(sellerId);
			int status = OrderQueryStatusEnum.SellerAccept.getValue();
			getsellerordersBean.setOrderStatus(status);
			String beginTime = YMTDateUtil.getBeforeOrNextDay(-1).replace(' ', 'T');
			String endTime = YMTDateUtil.getBeforeOrNextDay(5).replace(' ', 'T');
			getsellerordersBean.setBeginTime(beginTime);
			getsellerordersBean.setEndTime(endTime);
			int timeType = OrderQueryTimeTypeEnum.PayDate.getValue();
			getsellerordersBean.setTimeType(timeType);
			// getsellerordersBean.setOrderType(orderType);

			getsellerordersBean.setPageIndex(0);
			getsellerordersBean.setPageSize(10);

			getsellerordersCall.setData(getsellerordersBean);
			getsellerordersCall.callService();

			Logger.verifyEquals(ECode.ERROR400, getsellerordersCall.getCode(),
					"验证Code");
			Logger.verifyEquals(ECode.ERROR400_MSG_30,
					getsellerordersCall.getString("Msg"), "验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetSellerOrders_014() {
		Logger.start(false, "指定的每页显示条数超过200条");
		try {
			int sellerId = Integer.valueOf(EnvSetup.getData("BuyerId"));
			getsellerordersBean.setSellerId(sellerId);
			int status = OrderQueryStatusEnum.SellerAccept.getValue();
			getsellerordersBean.setOrderStatus(status);
			String beginTime = YMTDateUtil.getBeforeOrNextDay(-1).replace(' ', 'T');
			String endTime = YMTDateUtil.getBeforeOrNextDay(5).replace(' ', 'T');
			getsellerordersBean.setBeginTime(beginTime);
			getsellerordersBean.setEndTime(endTime);
			int timeType = OrderQueryTimeTypeEnum.PayDate.getValue();
			getsellerordersBean.setTimeType(timeType);
			// getsellerordersBean.setOrderType(orderType);

			getsellerordersBean.setPageIndex(1);
			getsellerordersBean.setPageSize(201);

			getsellerordersCall.setData(getsellerordersBean);
			getsellerordersCall.callService();

			Logger.verifyEquals(ECode.ERROR400, getsellerordersCall.getCode(),
					"验证Code");
			Logger.verifyEquals(ECode.ERROR400_MSG_31,
					getsellerordersCall.getString("Msg"), "验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetSellerOrders_015() {
		Logger.start(false, "指定的每页显示条数为0条");
		try {
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			getsellerordersBean.setSellerId(sellerId);
			int status = OrderQueryStatusEnum.SellerAccept.getValue();
			getsellerordersBean.setOrderStatus(status);
			String beginTime = YMTDateUtil.getBeforeOrNextDay(-1).replace(' ', 'T');
			String endTime = YMTDateUtil.getBeforeOrNextDay(5).replace(' ', 'T');
			getsellerordersBean.setBeginTime(beginTime);
			getsellerordersBean.setEndTime(endTime);
			int timeType = OrderQueryTimeTypeEnum.PayDate.getValue();
			getsellerordersBean.setTimeType(timeType);
			// getsellerordersBean.setOrderType(orderType);

			getsellerordersBean.setPageIndex(1);
			getsellerordersBean.setPageSize(201);

			getsellerordersCall.setData(getsellerordersBean);
			getsellerordersCall.callService();

			Logger.verifyEquals(ECode.ERROR400, getsellerordersCall.getCode(),
					"验证Code");
			Logger.verifyEquals(ECode.ERROR400_MSG_31,
					getsellerordersCall.getString("Msg"), "验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetSellerOrders_017() {
		Logger.start(true, "根据卖家ID批量查询订单成功, 商品有退货信息");
		try {
			int sellerId = Integer.valueOf(EnvSetup.getData("BuyerId"));
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			Logger.comment("准备前置数据");
			OrderCreate c = new OrderCreate();
			c.create4_RefundOrder(userId, sellerId);
			Thread.sleep(2000l);
			Logger.comment("完成准备前置数据");

			getsellerordersBean.setSellerId(sellerId);
			int status = OrderQueryStatusEnum.Received.getValue();
			getsellerordersBean.setOrderStatus(status);
			String beginTime = YMTDateUtil.getBeforeOrNextDay(-5).replace(' ', 'T');
			String endTime = YMTDateUtil.getBeforeOrNextDay(10).replace(' ', 'T');
			getsellerordersBean.setBeginTime(beginTime);
			getsellerordersBean.setEndTime(endTime);
			int timeType = OrderQueryTimeTypeEnum.CreateDate.getValue();
			getsellerordersBean.setTimeType(timeType);
			getsellerordersBean.setPageIndex(1);
			getsellerordersBean.setPageSize(10);
			getsellerordersCall.setData(getsellerordersBean);
			getsellerordersCall.callService();
			Logger.verifyEquals(ECode.SUCCESS, getsellerordersCall.getCode(),
					"验证Code");
			// verifyDb();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
}